home *** CD-ROM | disk | FTP | other *** search
-
- package sub_arctic.input;
-
- import sub_arctic.lib.sub_arctic_error;
-
- import java.util.Vector;
-
- /**
- * This is a subclass of focus_dispatch_agent designed to support agents
- * which need to limit their focus set to at most one element.
- *
- * @author Scott Hudson
- */
-
- public abstract class single_focus_agent extends focus_dispatch_agent {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Simple constructor */
- public single_focus_agent()
- {
- /* reclaim extra space since we know we are not larger than 1 */
- _focus_set.setSize(1);
- _user_info_set.setSize(1);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Replace the focus set of this agent with the given object. This provides
- * a causal event and an uninterpreted object that will be passed back to
- * the focus object whenever input is delivered to it by this agent.<p>
- *
- * @param focusable to_obj the object going in the focus set.
- * @param event evt the event that "caused" this focus.
- * @param Object user_info the uninterpreted information that we will pass
- * back to the object whenever it gets input from
- * this agent.
- */
- public void set_focus_to(focusable to_obj, event evt, Object user_info)
- {
- int i;
- focusable remove_obj;
- Object remove_info;
- boolean already_focus = false;
-
- /* make sure its ok to add */
- if (!allowable_focus(to_obj))
- throw new sub_arctic_error(
- "Attempt to add an ineligible object to the focus set");
-
- /* if they set to a null focus, treat that as a clear */
- if (to_obj == null)
- {
- clear_focus(evt);
- return;
- }
-
- /* pull out the old focus object */
- remove_obj = (focusable)_focus_set.elementAt(0);
- remove_info = _user_info_set.elementAt(0);
-
- /* we do something only if its a change */
- if (to_obj != remove_obj)
- {
- /* inform the old object about loss of focus */
- if (remove_obj != null) inform_focus_exit(remove_obj,evt,remove_info);
-
- /* put in the new object */
- _focus_set.setElementAt(to_obj, 0);
- _user_info_set.setElementAt(user_info, 0);
-
- /* tell it that it has the focus */
- inform_focus_enter(to_obj,evt,user_info);
- }
- }
-
- //had:
- //* @exception bad_value if this object is not suitable for inclusion in this
- //* focus set.
- //* @exception general
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Add object to focus set. For this subclass this replaces the current
- * focus hence acts the same as set_focus_to().
- *
- * @param focusable new_obj the object going in the focus set.
- * @param event evt the event that "caused" this focus.
- * @param Object user_info the uninterpreted information that we will pass
- * back to the object whenever it gets input from
- * this agent.
- */
- public void add_to_focus(focusable new_obj, event evt, Object user_info)
- {
- /* for singles this is the same as just setting the focus */
- set_focus_to(new_obj, evt, user_info);
- }
-
- //has:
- //* @exception bad_value if this object is not suitable for inclusion in this
- //* focus set.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Remove the given object from the focus set. If the object is in the
- * focus set this acts like clear_focus(). If not an exception is thrown.
- *
- * @param focusable obj the object going in the focus set.
- * @param event evt the event that "caused" this focus.
- */
- public void remove_from_focus(focusable obj, event evt)
- {
- Object user_info;
-
- /* if its not our focus we throw an exception */
- if (obj != _focus_set.elementAt(0))
- throw new sub_arctic_error(
- "Attempt to remove focus from an object not in the focus set");
-
- /* otherwise remove it and let it know */
- _focus_set.setElementAt(null, 0);
- user_info = _user_info_set.elementAt(0);
- _user_info_set.setElementAt(null, 0);
- inform_focus_exit(obj, evt, user_info);
- }
-
- //has:
- //* @exception bad_value if this object is not in the focus set.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Clear the focus set of this agent to empty.
- * @param event evt the event that "caused" this.
- */
- public void clear_focus(event evt)
- {
- focusable old;
- Object old_info;
-
- /* pull out the old focus */
- old = (focusable)_focus_set.elementAt(0);
- old_info = _user_info_set.elementAt(0);
-
- /* get rid of any focus */
- _focus_set.setElementAt(null, 0);
- _user_info_set.setElementAt(null, 0);
-
- /* if we really had an old focus let it now that its out. */
- if (old != null) inform_focus_exit(old, evt, old_info);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-